package yth.api.user.web;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import yth.api.user.entity.LogisticsUser;
import yth.api.user.model.LogisticsUserModel;
import yth.api.user.model.RetError;
import yth.api.user.model.RetMsg;
import yth.api.user.model.RetSuccess;
import yth.api.user.service.ILogisticsUserService;

@RestController
@RequestMapping("/logistics")
public class LogisticsUserController {
    
	private static Logger logger=LoggerFactory.getLogger(LogisticsUserController.class);
	
	@Autowired
	private ILogisticsUserService logisticsUserService;
	
	@RequestMapping(value="/users",method=RequestMethod.GET)
	public RetMsg findAll(){
		logger.info("logistics/users ---- start ");
		RetMsg retMsg=null;
		try {
			List<LogisticsUser>  lus=logisticsUserService.selectAll(new BigDecimal(11));
			List<LogisticsUserModel> lums=new ArrayList<>();
			for (LogisticsUser lu : lus) {
				LogisticsUserModel lum=new LogisticsUserModel();
				lum.setAccount(lu.getAccount());
				lum.setPwd(lu.getPwd());
				lum.setRepertoryId(lu.getRepertoryId());
				lum.setTel(lu.getTel());
				lum.setUserName(lu.getUsername());
				lum.setUserType(lu.getUsertype());
				lums.add(lum);
			} 
			retMsg=new RetSuccess(lums);
			 
		} catch (Exception e) {  
			logger.error(e.toString());
			retMsg=new RetError(40001,e.toString());
		}
		logger.info("logistics/users ---- end ");
		return retMsg;
	}
	 
	
}
